<?php
	global $_W,$_GPC;
	if($_W['role']){
		$skey = $_GPC['key'];
		$so = $_GPC['so'];
		if($so=='soorderid'&&!empty($skey)){
			$page = $_GPC['page'];
			$pindex = max(1, intval($page));	
			$psize = 5;
			$sql = "SELECT o.oid,o.orderid,o.book_id,o.is_pay,o.is_ok,o.pay_money,o.goods_money,o.details,o.addtime,o.order_type,g.titlepic  FROM".tablename('mii_ang_order')." o LEFT JOIN ".tablename('mii_ang_goods')." g ON o.goods_id = g.id  WHERE o.uniacid=:uniacid  AND o.orderid=:orderid ORDER BY o.oid DESC LIMIT ".($pindex-1)*$psize.','.$psize;
			$order = pdo_fetchall($sql,array(':uniacid'=>$_W['uniacid'],':orderid'=>$skey));
			$countSql = "SELECT COUNT(*)FROM " . tablename('mii_ang_order')." WHERE uniacid ={$_W['uniacid']} AND orderid = {$skey}";
			$total = pdo_fetchcolumn($countSql);
			$pager = pagination($total, $pindex, $psize,$url='',$context = array('before' =>1, 'after' => 1, 'ajaxcallback' => '', 'callbackfuncname' => ''));
			if($order){
				include $this->template('web/order/soorder');	
			}else{
				message('没有该订单');
			}	
					
		}elseif ($so=='somemberid'&&!empty($skey)) {
			$page = $_GPC['page'];
			$pindex = max(1, intval($page));	
			$psize = 5;
			$sql = "SELECT o.oid,o.orderid,o.book_id,o.is_pay,o.is_ok,o.pay_money,o.goods_money,o.details,o.addtime,o.order_type,g.titlepic  FROM".tablename('mii_ang_order')." o LEFT JOIN ".tablename('mii_ang_goods')." g ON o.goods_id = g.id  WHERE o.uniacid=:uniacid  AND o.uid=:uid ORDER BY o.oid DESC LIMIT ".($pindex-1)*$psize.','.$psize;
			$order = pdo_fetchall($sql,array(':uniacid'=>$_W['uniacid'],':uid'=>$skey));
			$countSql = "SELECT COUNT(*)FROM " . tablename('mii_ang_order')." WHERE uniacid ={$_W['uniacid']} AND uid = {$skey}";
			$total = pdo_fetchcolumn($countSql);
			$pager = pagination($total, $pindex, $psize,$url='',$context = array('before' =>1, 'after' => 1, 'ajaxcallback' => '', 'callbackfuncname' => ''));
			if($order){
				include $this->template('web/order/soorder');	
			}else{
				message('没有该订单');
			}					
		}elseif($so=='somembername'&&!empty($skey)){
			$sokey = substr(json_encode(array($skey)),2,-2);
			$sokey = str_replace('"','', $sokey);
			$sokey = str_replace("\\",'_', $sokey);
			$page = $_GPC['page'];
			$pindex = max(1, intval($page));	
			$psize = 5;
			$sql = "SELECT o.oid,o.orderid,o.book_id,o.is_pay,o.is_ok,o.pay_money,o.goods_money,o.details,o.addtime,o.order_type,g.titlepic  FROM".tablename('mii_ang_order')." o LEFT JOIN ".tablename('mii_ang_goods')." g ON o.goods_id = g.id  WHERE o.uniacid=:uniacid  AND o.details LIKE '%{$sokey}%' ORDER BY o.oid DESC LIMIT ".($pindex-1)*$psize.','.$psize;
			$order = pdo_fetchall($sql,array(':uniacid'=>$_W['uniacid']));
			$countSql = "SELECT COUNT(*)FROM " . tablename('mii_ang_order')." WHERE uniacid ={$_W['uniacid']} AND details LIKE '%{$sokey}%' ";
			$total = pdo_fetchcolumn($countSql);
			$pager = pagination($total, $pindex, $psize,$url='',$context = array('before' =>1, 'after' => 1, 'ajaxcallback' => '', 'callbackfuncname' => ''));
			if($order){
				include $this->template('web/order/soorder');	
			}else{
				message('没有该订单');
			}			
		}elseif($so=='somembermobile'&&!empty($skey)){
			$page = $_GPC['page'];
			$pindex = max(1, intval($page));	
			$psize = 5;
			$sql = "SELECT o.oid,o.orderid,o.book_id,o.is_pay,o.is_ok,o.pay_money,o.goods_money,o.details,o.addtime,o.order_type,g.titlepic  FROM".tablename('mii_ang_order')." o LEFT JOIN ".tablename('mii_ang_goods')." g ON o.goods_id = g.id  WHERE o.uniacid=:uniacid  AND o.details LIKE '%{$skey}%' ORDER BY o.oid DESC LIMIT ".($pindex-1)*$psize.','.$psize;
			$order = pdo_fetchall($sql,array(':uniacid'=>$_W['uniacid']));
			$countSql = "SELECT COUNT(*)FROM " . tablename('mii_ang_order')." WHERE uniacid ={$_W['uniacid']} AND details LIKE '%{$skey}%' ";
			$total = pdo_fetchcolumn($countSql);
			$pager = pagination($total, $pindex, $psize,$url='',$context = array('before' =>1, 'after' => 1, 'ajaxcallback' => '', 'callbackfuncname' => ''));
			if($order){
				include $this->template('web/order/soorder');	
			}else{
				message('没有该订单');
			}
		}elseif($so=='sopaybook'){
			$page = $_GPC['page'];
			$pindex = max(1, intval($page));	
			$psize = 5;
			$sql = "SELECT o.oid,o.orderid,o.book_id,o.is_pay,o.is_ok,o.pay_money,o.goods_money,o.details,o.addtime,o.order_type,g.titlepic  FROM".tablename('mii_ang_order')." o LEFT JOIN ".tablename('mii_ang_goods')." g ON o.goods_id = g.id  WHERE o.uniacid=:uniacid  AND o.order_type=:order_type ORDER BY o.oid DESC LIMIT ".($pindex-1)*$psize.','.$psize;
			$order = pdo_fetchall($sql,array(':uniacid'=>$_W['uniacid'],':order_type'=>'2'));
			$countSql = "SELECT COUNT(*)FROM " . tablename('mii_ang_order')." WHERE uniacid ={$_W['uniacid']} AND order_type = 2 ";
			$total = pdo_fetchcolumn($countSql);
			$pager = pagination($total, $pindex, $psize,$url='',$context = array('before' =>1, 'after' => 1, 'ajaxcallback' => '', 'callbackfuncname' => ''));
			if($order){
				include $this->template('web/order/soorder');	
			}else{
				message('没有该订单');
			}
		}elseif($so=='sobook'){
			$page = $_GPC['page'];
			$pindex = max(1, intval($page));	
			$psize = 5;
			$sql = "SELECT o.oid,o.orderid,o.book_id,o.is_pay,o.is_ok,o.pay_money,o.goods_money,o.details,o.addtime,o.order_type,g.titlepic  FROM".tablename('mii_ang_order')." o LEFT JOIN ".tablename('mii_ang_goods')." g ON o.goods_id = g.id  WHERE o.uniacid=:uniacid  AND o.order_type=:order_type ORDER BY o.oid DESC LIMIT ".($pindex-1)*$psize.','.$psize;
			$order = pdo_fetchall($sql,array(':uniacid'=>$_W['uniacid'],':order_type'=>'1'));
			$countSql = "SELECT COUNT(*)FROM " . tablename('mii_ang_order')." WHERE uniacid ={$_W['uniacid']} AND order_type = 1 ";
			$total = pdo_fetchcolumn($countSql);
			$pager = pagination($total, $pindex, $psize,$url='',$context = array('before' =>1, 'after' => 1, 'ajaxcallback' => '', 'callbackfuncname' => ''));
			if($order){
				include $this->template('web/order/soorder');	
			}else{
				message('没有该订单');
			}			
		}else{
			message('查询不到你找的订单');
		}	
	}else{
		message('没有操作权限');
	}
	function dejson($options,$key){
		$data = json_decode($options,true);
		return $data[$key];
	}
?>